package com.lazyJr.test.sort;

/**
 * Created by liuyangfx on 16-3-14.
 */
public class SelectionSort {

    public void sort(int[] a){
        for(int i=0;i<a.length;i++){
            int min=i;
            for(int j=i+1;j<a.length;j++){
                if(less(a[j],a[min])){
                    min = j;
                 }
            }
            exch(a,i,min);
        }
    }

    private boolean less(int v,int w){
        return (v - w) < 0;
    }

    private void exch(int[] a,int i,int j){
        int temp = a[i];
        a[i] = a[j];
        a[j] = temp;
    }

}
